package mysqlCodeGen.gen.utils;

import java.lang.reflect.Field;

/**
 * @author loser
 * @date 2023-01-09  17:19
 */
public class PropUtil {

    public static PropReader init(String file) {
        return new PropReader(file);
    }

    public static <T> T loadStrValue(Class<T> targetClass, String file, String pre) {

        T result = null;
        try {
            PropReader reader = init(file);
            result = targetClass.newInstance();
            Field[] fields = targetClass.getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                String value = reader.getValue(pre + "." + field.getName());
                if (field.getType() == String.class) {
                    field.set(result, value);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

}
